package com.bootdo.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.common.utils.DateUtils;
import com.bootdo.system.domain.TbStock;
import com.bootdo.system.domain.TbSvip;
import com.bootdo.system.domain.TbSvipExample;
import com.bootdo.system.mapper.TbStockMapper;
import com.bootdo.system.mapper.TbSvipMapper;
import com.bootdo.system.service.ProductService;

@Service
public class ProductServiceImpl implements ProductService{
	
	@Autowired
    private TbSvipMapper sm;
	
	@Autowired
    private TbStockMapper stockMapper;

	@Override
	public List<Map<String, Object>> list(Map<String, Object> map) {
		//调用时  实时获取卡盟该商品价格 带完善
		return sm.list(map);
	}

	@Override
	public int count(Map<String, Object> map) {
		return sm.count(map);
	}

	@Override
	public int insert2update(TbSvip table) {
		int res=0;
		if(table != null) {
			Integer id = table.getId();
			if(id != null) {
				res=sm.updateByPrimaryKeySelective(table);
			}else {
				table.setCreatetime(DateUtils.format(new Date()));
				res=sm.insertSelective(table);
			}
		}
		return res;
	}

	@Override
	public TbSvip getById(Integer id) {
		return sm.selectByPrimaryKey(id);
	}

	@Override
	public int batchremove(Integer[] ids) {
		int res=0;
		if(ids.length > 0) {
			for (int i = 0; i < ids.length; i++) {
				res=sm.deleteByPrimaryKey(ids[i]);
			}
		}
		return res;
	}

	@Override
	public int remove(Integer id) {
		return sm.deleteByPrimaryKey(id);
	}

	@Override
	public List<TbSvip> getSvipList() {
		TbSvipExample tbSvipExample = new TbSvipExample();
		return sm.selectByExample(tbSvipExample);
	}

	@Override
	public int insert2updateSto(TbStock table) {
		int res=0;
		if(table != null) {
			Integer id = table.getId();
			if(id != null) {
				res=stockMapper.updateByPrimaryKeySelective(table);
			}else {
				res=stockMapper.insertSelective(table);
			}
		}
		return res;
	}

	@Override
	public int removeSto(Integer id) {
		return stockMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int batchremoveSto(Integer[] ids) {
		int res=0;
		if(ids.length > 0) {
			for (int i = 0; i < ids.length; i++) {
				res=stockMapper.deleteByPrimaryKey(ids[i]);
			}
		}
		return res;
	}

	@Override
	public TbSvip getByStoId(Integer id) {
		TbStock selectByPrimaryKey = stockMapper.selectByPrimaryKey(id);
		if(selectByPrimaryKey != null) {
			String svipId = selectByPrimaryKey.getSvipId();
			return sm.selectByPrimaryKey(Integer.valueOf(svipId));
		}
		return null;
	}

	@Override
	public TbStock getByStoId2(Integer id) {
		return stockMapper.selectByPrimaryKey(id);
	}


}
